<?php
namespace Operationtest\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;

class TransfertTable extends AbstractTableGateway {
    protected $table = 'rh_transfert';
    
    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new \RHX\Model\Object\Transfert($this->adapter));
        $this->initialize();
    }
    
    public function getTransfertForDay($site, $day, $type) {
        return $this->select(function(Select $select) use($site, $day, $type) {
            $where = new Where();
            $where->equalTo('jour',$day);
            if($type == 'entrant') {
                $where->equalTo('arrivee', $site);
            } else {
                $where->equalTo('depart', $site);
            }
            $select->where($where);
            $select->order('matricule ASC');
        });
    }
}